package cn.edu.jxau.test;

public class Edge implements Comparable<Edge> {

    private final int v;
    private final int w;
    private final double weight;

    public Edge(int v, int w, double weight) {
        this.v = v;
        this.w = w;
        this.weight = weight;
    }

    public int either() {
        return v;
    }

    public int other(int i) {
        if (i == v) {
            return w;
        } else if (i == w) {
            return v;
        } else {
            throw new RuntimeException("并不依附于顶点v,v=" + v);
        }
    }

    public double weight() {
        return weight;
    }

    @Override
    public int compareTo(Edge e) {
        double cmp = weight - e.weight;
        if (cmp < 0) {
            return -1;
        } else if (cmp > 0) {
            return 1;
        } else {
            return 0;
        }
    }

    @Override
    public String toString() {
        return "Edge [v=" + v + ", w=" + w + ", weight=" + weight + "]";
    }
}
